package com.ctrl.riveradministrator.mvp.view.activity.contact;

import android.support.annotation.NonNull;

import com.ctrl.riveradministrator.util.Cn2Spell;

public class ContactClassified implements Comparable<ContactClassified> {

    private String name; // 姓名
    private String tel;//电话号码
    private String pinyin; // 姓名对应的拼音
    private String firstLetter; // 拼音的首字母

    public ContactClassified() {
    }

    public ContactClassified(String name,String phone) {
        this.name = name;
        this.tel = phone;
        pinyin = Cn2Spell.getPinYin(name); // 根据姓名获取拼音
        firstLetter = pinyin.substring(0, 1).toUpperCase(); // 获取拼音首字母并转成大写
        if (!firstLetter.matches("[A-Z]")) { // 如果不在A-Z中则默认为“#”
            firstLetter = "#";
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public String getFirstLetter() {
        return firstLetter;
    }

    public void setFirstLetter(String firstLetter) {
        this.firstLetter = firstLetter;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @Override
    public int compareTo(@NonNull ContactClassified contactClassified) {
        if (firstLetter.equals("#") && !contactClassified.getFirstLetter().equals("#")) {
            return 1;
        } else if (!firstLetter.equals("#") && contactClassified.getFirstLetter().equals("#")){
            return -1;
        } else {
            return pinyin.compareToIgnoreCase(contactClassified.getPinyin());
        }
    }
}
